

#include "QtStra2.h"
#include "QtStra2_InstTableDelegate.h"



QtStra2::QtStra2(QDockWidget* instDock, QDockWidget* strategyDock, QTabWidget::TabPosition pos, QWidget *parent): 
QtStraTemplate(2, instDock, strategyDock, pos, parent)
{
	m_instTable = new QTableWidget();
	m_instTable->setItemDelegate(new QtStra2InstTableDelegate);
	m_instTable->setSelectionBehavior(QAbstractItemView::SelectRows);
	m_instTable->setAlternatingRowColors(true);


	SetInstTable(m_instTable);

	InitInstTable();
}

QString QtStra2::DefaultInstTableValue(int col)
{
	return "1";
}

void QtStra2::SetUserdataNew()
{

	m_pstrauserdata->ClearNew();

	//get count
	int rowcnt = m_instTable->rowCount();
	int colcnt = m_instTable->columnCount();
	//
	//from every row
	for (int rowIndex = 0; rowIndex < rowcnt; rowIndex++)
	{
		Qt::CheckState c = m_instTable->item(rowIndex, 0)->checkState();

		//if checked
		if (Qt::Checked == c)
		{
			char inst[20] = {0}; int reqvol, stopcnt;

			//from every column
			for (int colIndex = 0; colIndex < colcnt; colIndex++)
			{
				QTableWidgetItem* item =  m_instTable->item(rowIndex, colIndex);


				if (0 == colIndex)
					strcpy(inst, item->text().toStdString().c_str());		
				else if (1 == colIndex)
					reqvol = item->text().toInt();
				else if (2 == colIndex)
					stopcnt = item->text().toInt();
			}



			QtStraUserdataCore<userdata_stra2>::QtStraData barrlt;
			{
				BarInfo& bar = barrlt.bar;
				strcpy(bar.instru, inst);
				bar.type = tick;
				bar.cnt = 1;
				//barrlt.timertype = timertype;
				userdata_stra2& userdata = barrlt.userdata;
				userdata.vol = reqvol;
				userdata.stopcnt = stopcnt;
			}




			//add new
			m_pstrauserdata->AddNew(barrlt);

		}

	}
}



